import { Link } from 'react-router-dom';
import { Tooltip } from 'antd';
// import { getLocationSearchStr } from '@/utils';

// 把传入得对象拼成url search所需的字符串格式 {} -> ''
export const getLocationSearchStr = (oSearch = {}) => {
  const aSearch = [];
  for (const i in oSearch) {
    if (oSearch[i]) {
      aSearch.push(`${i}=${oSearch[i]}`);
    }
  }
  return aSearch.join('&');
};

const TransLink = (props) => {
 
  const { linkUrl, searchConfig, children, isInner, isNoEllipsis } = props;
  const search = getLocationSearchStr(searchConfig);
  // if (isMicroApp && isInner) {
  //   return (
  //     <div
  //       className="dt-custom-theme-color"
  //       style={{
  //         cursor: 'pointer',
  //       }}
  //       onClick={() => {
  //         window.history.pushState(
  //           searchConfig,
  //           null,
  //           `${window.location.origin}/catalog-mng/v2/cspui#${linkUrl}?${search}`
  //         );
  //       }}
  //     >
  //       {!isNoEllipsis ? (
  //         <Tooltip isWhiteTipBg placement="bottom" title={children || ''} monitorWindowResize>
  //           {children}
  //         </Tooltip>
  //       ) : (
  //         children
  //       )}
  //     </div>
  //   );
  // }
  return (
    <Link
      to={{
        pathname: linkUrl,
        search: search ? `?${search}` : null,
      }}
    >
      {!isNoEllipsis ? (
        <Tooltip isWhiteTipBg placement="bottom" title={children || ''} monitorWindowResize>
          {children}
        </Tooltip>
      ) : (
        children
      )}
    </Link>
  );
};
export default TransLink;
